package cn.doctor.assistant.pad.api.hudong;

import android.util.Log;

import com.alibaba.fastjson.JSON;
import com.android.volley.Response;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.doctor.assistant.pad.MyApplication;
import cn.doctor.assistant.pad.api.AssistAPI;
import cn.doctor.assistant.pad.api.bean.AssResponse;
import cn.doctor.assistant.pad.api.bean.ReqBean;
import cn.doctor.assistant.pad.base.AssJsonRequest;
import cn.doctor.assistant.pad.base.ResultCallback;
import cn.doctor.assistant.pad.entity.GroupsBean;

/**
 * Created by jiaolf on 2016/4/25.
 */
public class ChatApi {
    public static final String METHOD_GET_CONTACT_GROUP = "GetGroupByType";

    public static void getContactGroupsByType(final ResultCallback<List<GroupsBean>> callback) {
        Map<String, Long> params = new HashMap<>();
        String id = MyApplication.getInstance().mCurrDoctor.getId();
        params.put("id", Long.valueOf(id));
        ReqBean reqBean = ReqBean.newInstance(METHOD_GET_CONTACT_GROUP, params);
        String jsonPrams = reqBean.toJsonString();

        AssJsonRequest jsonRequest = new AssJsonRequest(jsonPrams, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                Log.d("jzsn", response);
                AssResponse assResp = JSON.parseObject(response, AssResponse.class);
                List<GroupsBean> list = JSON.parseArray(assResp.getResult().getData(), GroupsBean.class);
                callback.onSuccess(list);
            }
        });

        AssistAPI.getRequestQueue().add(jsonRequest);
    }
}
